package com.whisperarts.financer.app.actions;

import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

import com.whisperarts.financer.app.editors.AccountEditorInput;
import com.whisperarts.financer.app.editors.TransactionsEditor;
import com.whisperarts.financer.model.account.Account;

public class ActionsFactory {
	
	public static void doOpenAccountAction(Account account, IWorkbenchWindow window) {
		IWorkbenchPage page = window.getActivePage();
		AccountEditorInput input = new AccountEditorInput(account);
		try {
			page.openEditor(input, TransactionsEditor.ID);
		} catch (PartInitException e) {
			// handle error
			e.printStackTrace();
		}
	}
	
	public static void showView(String viewId) {
		try {
			PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(viewId);
		} catch (PartInitException e) {
			e.printStackTrace();
		}
	}
	
}
